package analysis.ProfessionalTop10;

import analysis.Profess;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class ProfessionalTop10Mapper extends Mapper<LongWritable, Text, IntWritable, Profess> {
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String[] lines = value.toString().split(" ");
        int number = Integer.parseInt(lines[1]);    // 招生人数
        Profess profess = new Profess(lines[0], number);    // 用专业代码和招生人数创建Profess对象存储
        //键值固定为1，这样才能把所有profess对象放进同一个数组进行比较
        context.write(new IntWritable(1), profess);
    }
}
